package com.walker.routing;

import com.rabbitmq.client.*;
import com.walker.BaseConfig;


public class RoutingSender {

    public static final String EXCHANGE_02 = "waring.exchange.02";
    public static final String ROUTING_01 = "waring.exchange.01";

    public static ConnectionFactory connectionFactory() {
        ConnectionFactory connectionFactory = new ConnectionFactory();
        connectionFactory.setHost(BaseConfig.HOST);
        connectionFactory.setVirtualHost(BaseConfig.VHOST);
        connectionFactory.setPort(5672);
        connectionFactory.setUsername(BaseConfig.USERNAME);
        connectionFactory.setPassword(BaseConfig.PASSWORD);
        return connectionFactory;
    }

    public static void main(String[] args) throws Exception {
        ConnectionFactory connectionFactory = connectionFactory();
        Connection connection = connectionFactory.newConnection();
        Channel channel = connection.createChannel();
        channel.exchangeDeclare(EXCHANGE_02, BuiltinExchangeType.DIRECT);
        for (int i = 0; i < 10; i++) {
            byte[] body = ("张三，你好,"+i).getBytes();
            channel.basicPublish(EXCHANGE_02, "waring.green", MessageProperties.PERSISTENT_TEXT_PLAIN, body);
        }

    }
}
